function getUserInfo() {
  $.ajax({
    method: "GET",
    url:'/my/userinfo',
    // headersgi固定写法
    headers: {
        Authorization:localStorage.getItem('token')
    },
    success:function(res){
        if(res.status!==0){
          return layui.layer.msg('获取用户信息失败')
        }
        renderAvatar(res.data);
    }
  });
}
// 渲染头像
function renderAvatar(user){
  var name =user.nickname || user.username
  // console.log(name);
  $('.welcome').html('欢迎&nbsp;&nbsp;'+name)
  // console.log( $('.welcome'));
  // $('.qqqq').html('hahah')
  if(user.user_pic!==null){
    $('.layui-nav-img').attr('src',user.user_pic).show()
    $('.text-avatar').hide()
  }else{
    // $('.layui-nav-img').hide()
    var first=name[0].toUpperCase()
    $('.text-avatar').html(first).show()
}
}
$(function () {
  getUserInfo()
 
  

// 退出功能
$("#btnLogout").on('click',function(){
  layer.confirm('确定退出吗?傻狗?', {icon: 3, title:'提示'}, function(index){
    localStorage.removeItem('token')
    location.href='login.html'
    layer.close(index);
  });
         
})
})
